/*
Author: Jason Bareswilt
Program: GameMap
Functionality: This class will create the array that will get colored over the main map.  this will also interact directly with the block class
Version: 0.1.0
Date written: November 15, 2011
Date tested:
Todo: fix display problem when linking up - FIXED
 */

package disease;

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;

import disease.Block;
import disease.RandomNumber;
import disease.Account;
import disease.Subway;

public class GameMap implements MouseListener
{
	static RandomNumber randNum = new RandomNumber();
	static Account money = new Account();  //<-- so we can acess our money
	static Score score = new Score();
	public static int size = 40;
	static Block[][] map;  // the map   we need to draw it
	private static Block[] cities_left; // the list of blocks with a population
	public static Subway subway;//RW: <-- 10 people saved by a train
	public static PoliceStation police;
	public static DrawingArea panel;
	public static JTextField textField;
	public static Hospital hospital;
	public static Airport airport;
	public static Arena arena;
	private static boolean speedUp = false;
	private static boolean slowDown = false;
	private static boolean normalSpeed = true;
	private static int delay = 1;//this will be used in thread.sleep
	private static String gameName = "";
	static int difficulty = 2;  //medium by default
	
	//public static int page = 1;
	public void gameMapGUI(String GameName, int hardness)
	{
		//this function creates the gui for the actuall game
		System.out.println("GameMap");
		gameName = GameName;
		System.out.println(gameName);
		//set the difficulty
		difficulty = hardness;//sets difficulty
		//create classes
		arena = new Arena("Arena");
		airport = new Airport("Airport",20);
		hospital = new Hospital("Hospital");
		police = new PoliceStation("Police Station");
		subway = new Subway("Subway",10);
		//create the blocks for the map
		map = new Block[size][size];
		//deadSpotExists = false;
	    cities_left = new Block[size*size];
	    int xLoc = randNum.getPositiveRandomNumber(size);
	    int yLoc = randNum.getPositiveRandomNumber(size);
	    System.out.println("xLoc: " + xLoc);
	    System.out.println("yLoc: " + yLoc);
	    for ( int i = 0; i < size; i++){
	        for(int j = 0; j < size; j++) {
	            //block(int x_value, int y_value, int h_pop, int tot_h_pop, String location)
	          	int num = randNum.getPositiveRandomNumber();
	        	//System.out.println(num%100 + ":"+num%100+1);
	            map[i][j]= new Block(i,j,(num%1000)+1,(num%1000)+1,"Some place",xLoc,yLoc);
	            cities_left[i*size+j] = map[i][j];            
	        }
	    }
		RottingFlesh.frame.getContentPane().removeAll();
		//Depending of difficulty choose a map
		if(difficulty == 1){
			//easy
			panel = new DrawingArea(new ImageIcon("images/atlanta.jpg").getImage());
		}else if (difficulty == 2){
			//medium
			panel = new DrawingArea(new ImageIcon("images/lasevgas.jpg").getImage());
		}else if (difficulty == 3){
			//hard
			panel = new DrawingArea(new ImageIcon("images/phoenix.jpg").getImage());
		}else{
			System.out.println("ERROR:  difficulty not set properly");
		}
		//set the panel up to display the game properly
		panel.addMouseListener(this);//<-- allows us to click the panel
		//DrawingArea drawingArea = new DrawingArea();
		textField = new JTextField( );
		
		
		
		RottingFlesh.frame.getContentPane().add(panel);//<-- add panel to game
		RottingFlesh.frame.getContentPane().add(textField, BorderLayout.SOUTH);//<--adds dialog box at bottom
		//RottingFlesh.frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		RottingFlesh.frame.setLocation((screen.width / 2) - 400, (screen.height / 2) - 400);
		RottingFlesh.frame.setSize(900, 859);
		RottingFlesh.frame.setResizable(true);
		RottingFlesh.frame.setVisible(true);
		System.out.print("set up the game");
		//sets the variables to a default value
		normalSpeed = true;
		slowDown = false;
		speedUp = false;
		delay = 1;
		money.resetMoney();
		score.resetScore();	
		
		  class UpdateThread implements Runnable
	        {
			  //create a thread for the game to execute.  fixed our problem
	            public void run()
	            {
	                while (populationsLeft() > 0)
	                {
	                	Execute();
	                }
	            }
	        }
		  
		  final UpdateThread t = new UpdateThread();
	      new Thread(t).start();//<-- start the thread
	}	
	
	
	public static void Execute(){
	    checkEntireOrder();//<--sorts the priorityQueue
		int peopleDied = 0;
		int zombieTotal = 0;
	    while(populationsLeft() > 0){  //<-- till the array_of_populations
	    	//game logic
	    	//decides how much we should increment score and money by
	    	int amountToInc = 0;
	    	if(arena.isBuildingOpenOrClosed()){
	    		amountToInc += arena.getMoneyMultiplier();//if arena open
	    	}
	    	if(subway.isBuildingOpenOrClosed()){
	    		amountToInc++;//if subway open
	    	}
	    	if(airport.isBuildingOpenOrClosed()){
	    		amountToInc++;//if airport open
	    	}
	    	score.incrementScore(amountToInc+(difficulty-1));//this is a hardness bonus
	    	money.incrementMoney(amountToInc+2-difficulty);//difficulty taken into acount
	    		      	
	      	int randomActOfChance = randNum.getPositiveRandomNumber(20);//<--decides what the program is gonig to do next
	      	if(randomActOfChance<15){//convert human to zombie	      		
	      		//this is 75% of the time
	      		randomActOfChance = randomActOfChance%5;
	      		if(randomActOfChance > cities_left.length){
	      			//mods the number by the cities_left number so we don't get an error
	      			if(cities_left.length == 1){
	      				randomActOfChance = 1;
	      			}else{
	      				randomActOfChance = randomActOfChance%(cities_left.length-1);
	      			}
	      			if(randomActOfChance == cities_left.length){
	      				randomActOfChance -= 1;
	      			}
	      		}
	      		int attackLocation = 0;
	      		//which palce to attack
	      		//if(!deadSpotExists){
	      			//int randomAttackLocation = rand_num.getPositiveRandomNumber(cities_left.length);
	      			//attackLocation = randomAttackLocation;
	      		//}
	      		if(randomActOfChance != 0){
	      			if(cities_left[attackLocation].getQuarentined() > 0){
	      				//if block is quarentined
	      				cities_left[attackLocation].zombieAttackQuarentine();
	      				score.incrementScore(1);
	      			}else{
	      				//if block isn't quarentined
	      				if(randomActOfChance%2 == 0 && police.getForceSize()>0){
	      					//50/50 chance of a cop being killed
	      					police.killCops(randomActOfChance/2);
	      				}
	      				double amountToConvert = randomActOfChance+amountToInc * hospital.getSaveRate();
	      				int amountToKill = randomActOfChance+amountToInc - (int)amountToConvert;
	      				cities_left[attackLocation].convertHumanToZombie((int)amountToConvert);
	      				cities_left[attackLocation].killHuman(amountToKill);
	      				zombieTotal += (int)amountToConvert;
	      				peopleDied += amountToKill;
	      			}
	      			cities_left[attackLocation].incrememntInfectionChance(2+amountToInc);
	      		}//else we don't want to convert human to zombie
	      		//gather block infor to attack around it
	      		int tempXCoord = cities_left[attackLocation].getXCoord();
	      		int tempYCoord = cities_left[attackLocation].getYCoord();
	      		for(int i = -1; i<2; i++){
	      			for(int j = -1; j<2; j++){
	      				//hits every adjacent block
	      				if((tempXCoord+i > 0) &&(tempXCoord+i < size)&&(tempYCoord+j > 0)&&(tempYCoord+j < size)){
	      					if(map[tempXCoord+i][tempYCoord+j].inQueue()){
		      					int randomChanceOfAct3 = randNum.getPositiveRandomNumber();
		      					if(randomChanceOfAct3%7 > 4){
		      						//3/7 percent of the time
		      						randomChanceOfAct3 = randomChanceOfAct3%5;
		      						if(randomChanceOfAct3 != 0){
		      							//66% of the time
		      							map[tempXCoord+i][tempYCoord+j].incrememntInfectionChance(1+amountToInc/2);
		      							if(map[tempXCoord+i][tempYCoord+j].getQuarentined() > 0){
		      								map[tempXCoord+i][tempYCoord+j].zombieAttackQuarentine();
		      								score.incrementScore(1);
		      							}else{
		      							//chance to kill policeman
		      					      	//if so decrease force size		      								
		      								double amountToConvert = randomChanceOfAct3%5+amountToInc/2 * hospital.getSaveRate();
		      								int amountToKill = randomChanceOfAct3%5+amountToInc/2 - (int)amountToConvert;
		      								map[tempXCoord+i][tempYCoord+j].convertHumanToZombie((int)amountToConvert);
		      								map[tempXCoord+i][tempYCoord+j].killHuman(amountToKill);
		      								zombieTotal += (int)amountToConvert;
		      			      				peopleDied += amountToKill;
		      							}
		      						}
		      					}
		      				}
	      				}//map in queue	
	      			}//inner for loop
	      		}//outter for loop
	      		if(cities_left[0].getHumanPopulation() == 0 ){
		      		//delete the block from the list
	      			cities_left[0].deleteFromQueue();
		      		cities_left = remove(0);
		      		checkEntireOrder();//<-- sort cities_left
		      	}
	      	}else if(randomActOfChance<17){
	      		//this is 15 % of the time
	      		//kill cops
	      		int chance = randNum.getPositiveRandomNumber();
	      		if(randomActOfChance%3 != 0 && police.getForceSize()>0 && (chance&(difficulty*2)) <= 1){
  					//66% chance of a cop being killed
  					police.killCops(randomActOfChance/2);
  				}
	      		cities_left[0].killHuman(randomActOfChance%5);
	      		cities_left[0].incrememntInfectionChance(1);
	      		//human dies
	      	}else if(randomActOfChance<18){
	      		//happens 5% of the time
	      		//people escapes in subway or plane
	      		//if they are closed convert human to zombie
	      		int chance = randNum.getPositiveRandomNumber();
	      		if(subway.isBuildingOpenOrClosed() && (chance%(difficulty) == 1)){
	      			//if open
	      			subway.peopleEscape();
	      			score.incrementScore(250);
	      			//might want to subtract some amount of population from a block here
	      		}else if(airport.isBuildingOpenOrClosed() && (chance%(difficulty) == 0)){
	      			airport.peopleEscape();
	      			score.incrementScore(250);
	      		}else{
	      			double amountToConvert = 10+amountToInc * hospital.getSaveRate();
					int amountToKill = 10+amountToInc - (int)amountToConvert;
	      			cities_left[0].convertHumanToZombie((int)amountToConvert);
	      			cities_left[0].killHuman(amountToKill);
	      			zombieTotal += (int)amountToConvert;
      				peopleDied += amountToKill;
	      		}
	      		
	      	}else{
	      		//this is 5% of the time
	      		//zombie dies
	      		int dead_zombies = randomActOfChance%5;
	      		cities_left[0].killZombie(dead_zombies);
	      		cities_left[0].incrememntInfectionChance((dead_zombies)*-1);
	      		score.incrementScore(dead_zombies);
	      	}  	
	      	panel.updateUI();//<-- repaint the GUI
      	try {
			Thread.sleep(delay);//<-- this value will change accordingly to the speed up or slow down buttons
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
      }// end while
	    
	  //the game is over here...
	  //send highScore
	  HighScorelog.addScore(gameName, score.getScore());
	  textField.setText("Zombies: " + zombieTotal + " | peopleDied: " + peopleDied);
	  try {
		Thread.sleep(5000);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	//go back to main menu
	RottingFlesh.frame.setSize(450, 450);
	RottingFlesh.createAndShowGUI();	    
  }
	
	 public static Block[] remove(int index) 
		{//resizes the array
			cities_left[index] = cities_left[cities_left.length - 1];
			Block[] newArray = new Block[cities_left.length - 1];
			for(int i = 0; i<cities_left.length - 1;i++){
				newArray[i] = cities_left[i];
			}
			//deadSpotExists = true;
			return newArray;
		}
	
	 public static int populationsLeft(){
	  	//tells the number of cities with populations left
	  	return cities_left.length;
	  }
	
	 public static int getDifficulty(){
		 //returns the game difficulty
		 return difficulty;
	 }
	 
	  public static void checkEntireOrder(){
			//this is a more comprehensive but expensive way to make sure we have the correct order
			for (int j = 0; j < cities_left.length; j++){
				for( int i = cities_left.length -1; i >=0; i--){
					//starts at the back and checks the child and it's parents
					//if parent > child then switch
					int parent = i/2;
					//if(cities_left[i].getAlpha() < cities_left[parent].getAlpha()){
					if(cities_left[i].getDistance() < cities_left[parent].getDistance()){
						//need to switch
						//switchBlocks(i,parent);  //<-- looks like this isn't needed
						Block temp = new Block();
						temp = cities_left[i];
						cities_left[i] = cities_left[parent];
						cities_left[parent] = temp;

					}//end if
				}//end for
			}//end for
	  }//end check_entire_order
	  
	static class DrawingArea extends JPanel
	{		
		//class to draw GUI
		private static final long serialVersionUID = 1L;
		private static Image img;
		public DrawingArea(String filename)
		{
			//grabs the image
			this(new ImageIcon(img).getImage());
		}

	  	  public DrawingArea(Image img) {
	  		  //gets image data
	  	    DrawingArea.img = img;
	  	    Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
	  	    setPreferredSize(size);
	  	    setMinimumSize(size);
	  	    setMaximumSize(size);
	  	    setSize(size);
	  	    setLayout(null);
	  	  }
	  	public DrawingArea()
		{
	  		//empty constructor
		}
	  	
	      public void paintComponent(Graphics g){
	    	//over rides the paint component
	    	int x_offset = 130;//<-- the width of the button pane
	    	g.setColor(Color.GRAY);
	    	g.fillRect(0, 0, x_offset, 800);//gray background
	    	g.setColor(Color.BLACK);
	      	g.drawImage(img, x_offset, 0, null);//the background map
	      	Font font = new Font("Serif", Font.BOLD, 12);
	      	g.setFont(font);//new game font
	      	g.drawString("Money:",10,90);
	      	g.drawString(Integer.toString(money.getMoney()), 60, 90);//<--display money
	      	g.drawString("Score:",10,70);
	      	g.drawString(Integer.toString(score.getScore()), 60, 70);//<--display score
	      	//displays blocks on the map
	          for ( int i = 0; i < size; i++){
	              for(int j = 0; j < size; j++) {
	                  Color color;
	                  color = new Color(map[i][j].getRed(),map[i][j].getGreen(),map[i][j].getBlue(),(map[i][j].getAlpha()));
	                  g.setColor(color);
	                  g.fillRect(i*20+x_offset, j*20, 19, 19);
	                  if(map[i][j].getQuarentined() > 0){
	                	  //draw a red box around the square if quarentined 
	                	  Color color_red = new Color(255,0,0,(int) (255*map[i][j].getQuarentined()));
	                	  g.setColor(color_red);
	                	  g.drawRect(i*20+x_offset, j*20, 19, 19);//<--might be 20 on size
	                  }
	              }
	          }
	          //Upgrade buttons
	          g.setColor(Color.WHITE);
	          g.drawString("Upgrades",10,150);
	          int y_dist = 40;
	          String price = "";
	          //different facility names
	          String[] buttonNames = {"Hospital","Police Station","Airport","Subway","Arena",};
	          for(int i = 0; i < buttonNames.length; i++){
	        	  g.setColor(Color.darkGray);
	        	  if(i == 0 ){	        
	        		  //gets price
	        		  price = Integer.toString(hospital.getUpgradeCost());
	        		  if(hospital.getMaxLevel()){
	        			  price = "Max";
	        		  }
	        		  else if (money.getMoney() > hospital.getUpgradeCost() && hospital.isBuildingOpenOrClosed()){
	        			  //facility is open and can be upgrade
	        			  g.setColor(Color.GREEN);
	        		  }  
	        	  }else if(i == 1){	
	        		//gets price
	        		  price = Integer.toString(police.getUpgradeCost());
	        		  if(police.getMaxLevel()){
	        			  price = "Max";
	        		  }
	        		  else if (money.getMoney() > police.getUpgradeCost() && police.isBuildingOpenOrClosed()){//PoliceStation
	        			  g.setColor(Color.GREEN);
	        		  }	        	        		  
	        	  }else if(i == 2){
	        		//gets price
	        		  price = Integer.toString(airport.getUpgradeCost());
	        		  if(airport.getMaxLevel()){
	        			  price = "Max";
	        		  }
	        		  else if (money.getMoney() > airport.getUpgradeCost() && airport.isBuildingOpenOrClosed()){//Airport
	        			//facility is open and can be upgrade
	        			  g.setColor(Color.GREEN);
	        		  }	        		  
	        	  }else if(i == 3){
	        		//gets price
	        		  price = Integer.toString(subway.getUpgradeCost());
	        		  if(subway.getMaxLevel()){
	        			  price = "Max";
	        		  }
	        		  else if (money.getMoney() > subway.getUpgradeCost() && subway.isBuildingOpenOrClosed()){//Subway
	        			//facility is open and can be upgrade
	        			  g.setColor(Color.GREEN);
	        		  }	        		  
	        	  }else if(i == 4){
	        		//gets price
	        		  price = Integer.toString(arena.getUpgradeCost());
	        		  if(arena.getMaxLevel()){
	        			  price = "Max";
	        		  }
	        		  else if (money.getMoney() > arena.getUpgradeCost() && arena.isBuildingOpenOrClosed()){//Arena
	        			//facility is open and can be upgrade
	        			  g.setColor(Color.GREEN);
	        		  }	        		  
	        	  }
	        	  //draw button
		          g.fillRect(10, 160+i*y_dist, x_offset-20, 30);
		          g.setColor(Color.BLACK);
		          //draw facility type name
		          g.drawString(buttonNames[i], 20, 175+i*y_dist);
		          //draw price
		          g.drawString(price,20,185+i*y_dist);
	          }
	          g.setColor(Color.WHITE);
	          g.drawString("Store", 10, 400);
	          //draw store items
	          String[] storeNames = {"Buy Antidote","Recruit Army","Increase Security"};
	          price = "";
	          for(int i = 0; i < storeNames.length; i++){
	        	  g.setColor(Color.darkGray);
	        	  if(i == 0 ){
	        		//gets price
	        		  price = Integer.toString(hospital.getAntidoteCost());	        		  
	        		  if( money.getMoney() > hospital.getAntidoteCost()){
	        			  //can buy item
	        			  g.setColor(Color.GREEN);
	        		  }
	        	  }else if(i == 1 ){
	        		//gets price
	        		  price = Integer.toString(police.getArmyCost());        		  
	        		  if(money.getMoney() > police.getArmyCost()){
	        			//can buy item
	        			  g.setColor(Color.GREEN);
	        		  }
	        	  }else if(i == 2){
	        		//gets price
	        		  price = Integer.toString(police.getIncreaseSecurityCost());	        		
	        		  if (money.getMoney() > police.getIncreaseSecurityCost()){
	        			//can buy item
	        		 	g.setColor(Color.GREEN);
	        		  }
	        	  }
	        	  //draw button
		          g.fillRect(10, 410+i*y_dist, x_offset-20, 30);
		          g.setColor(Color.BLACK);
		          //draw item names
		          g.drawString(storeNames[i], 20, 425+i*y_dist);
		          //draw price
		          g.drawString(price, 20, 435 + i*y_dist);
	          }
	          //on off buttons
	          g.setColor(Color.WHITE);
	          g.drawString("Turn on/off",10,550);
	          for(int i = 2; i < buttonNames.length; i++){
	        	 if(i == 2 && airport.isBuildingOpenOrClosed()){//Airport
	        		  g.setColor(Color.GREEN);
	        		//button on
	        	  }else if(i == 3 && subway.isBuildingOpenOrClosed()){//Subway
	        		  g.setColor(Color.GREEN);
	        		//button on
	        	  }else if(i == 4 && arena.isBuildingOpenOrClosed()){//Arena
	        		  //button on
	        		  g.setColor(Color.GREEN);
	        	  }else{
	        		  //button off
	        		  g.setColor(Color.darkGray);
	        	  }
	        	 //draw button
		          g.fillRect(10, 560+(i-2)*y_dist, x_offset-20, 30);
		          g.setColor(Color.BLACK);
		          g.drawString(buttonNames[i], 20, 575+(i-2)*y_dist);
	          }
	          
	          //fast forward arrow
	          Color GOLD = new Color(255,215,0);
	          //if speed up
	          if(speedUp){
	        	  g.setColor(GOLD);  
	          }else{
	        	  g.setColor(Color.YELLOW); 
	          }
	          int[] xPoints = {50,50,60};
	          int[] yPoints = {770,790,780};
	          g.fillPolygon(xPoints, yPoints, 3);
	          
	          //normal button
	          if(normalSpeed){
	        	  g.setColor(GOLD);  
	          }else{
	        	  g.setColor(Color.YELLOW); 
	          }
	          g.fillOval(30, 770, 10, 20);
	          //slow down arrow
	          if(slowDown){
	        	  g.setColor(GOLD);  
	          }else{
	        	  g.setColor(Color.YELLOW); 
	          }
	          int[] xPoints2 = {20,20,10};
	          int[] yPoints2 = {770,790,780};
	          g.fillPolygon(xPoints2, yPoints2, 3);
	          
	          //when the game ends
	          if(populationsLeft() == 0)
	          {
	        	  Font fontLarge = new Font("Serif", Font.BOLD, 32);
	        	  g.setFont(fontLarge);
	        	  Color faintBlack = new Color(0,0,0,128);
	        	  g.setColor(faintBlack);
	        	  g.fillRect(0, 0, 900, 825);
	        	  g.setColor(Color.RED);
	        	  g.drawString("GAME OVER!!!",370,400);
	        	  Font fontMedium = new Font("Serif", Font.BOLD, 20);
	        	  g.setFont(fontMedium);
	        	  g.drawString("Score: " + score.getScore(),370,450);
	        	  g.drawString("Returning to Main Menu...", 370, 500);
	      	  } 
	      }    
//			g.drawString("Upgrade your city's buildings to help you hold off the infection, cure people if", 8, 135);
	}
	@Override
	public void mouseClicked(MouseEvent e) {		
		if(e.getX() > 10 && e.getX() < 120 && e.getY() > 160 && e.getY() < 190){
			//Hospital
			//System.out.println("You clicked the hospital button");
			if(money.getMoney() >= hospital.getUpgradeCost() && hospital.canUpgrade()){
				
				money.decreaseMoney(hospital.getUpgradeCost());//<-- amount subject to change
				hospital.upGradeHospital();
				score.incrementScore(1000);//<-- we can change
				textField.setText("Hospital upgraded");
			}else if (money.getMoney() < hospital.getUpgradeCost()){
				
				textField.setText("you don't have enough money to upgrade the hospital");
			}
			else{
				textField.setText("you can't upgrade the hospital at this time");
			}
		}else if(e.getX() > 10 && e.getX() < 120 && e.getY() > 200 && e.getY() < 230){
			//Police Station
			//System.out.println("You clicked the police button");
			if(money.getMoney() >= police.getUpgradeCost() && police.canUpgrade()){
				
				money.decreaseMoney(police.getUpgradeCost());//<-- amount subject to change
				police.upgradePolice();
				score.incrementScore(1000);//<-- we can change
				textField.setText("Polcie Station upgraded");
			}else if (money.getMoney() < police.getUpgradeCost()){
				
				textField.setText("you don't have enough money to upgrade the police");
			}
			else{
				textField.setText("you can't upgrade the police at this time");
			}
		}else if(e.getX() > 10 && e.getX() < 120 && e.getY() > 240 && e.getY() < 270){
			//Airport
			//System.out.println("You clicked the Airport button");
			if(money.getMoney() >= airport.getUpgradeCost() && airport.canUpgrade()){
				
				money.decreaseMoney(airport.getUpgradeCost());//<-- amount subject to change
				airport.upgradeAirport();
				score.incrementScore(1000);//<-- we can change
				textField.setText("Airport upgraded");
			}else if (money.getMoney() < airport.getUpgradeCost()){
				
				textField.setText("you don't have enough money to upgrade the airport");
			}
			else{
				textField.setText("you can't upgrade the airport at this time");
			}
		}else if(e.getX() > 10 && e.getX() < 120 && e.getY() > 280 && e.getY() < 310){
			//Subway
			//System.out.println("You clicked the Subway button");
			if(money.getMoney() >= subway.getUpgradeCost() && subway.canUpgrade()){
				
				money.decreaseMoney(subway.getUpgradeCost());//<-- amount subject to change
				subway.upgradeSubway();
				score.incrementScore(1000);//<-- we can change
				textField.setText("Subway upgraded");
			}else if (money.getMoney() < subway.getUpgradeCost()){
				
				textField.setText("you don't have enough money to upgrade the subway");
			}
			else{
				textField.setText("you can't upgrade the subway at this time");
			}
		}else if(e.getX() > 10 && e.getX() < 120 && e.getY() > 320 && e.getY() < 350){
			//Arena
			//System.out.println("You clicked the arena button");
			if(money.getMoney() >= arena.getUpgradeCost() && arena.canUpgrade()){
				
				money.decreaseMoney(arena.getUpgradeCost());//<-- amount subject to change
				arena.upgradeArena();
				score.incrementScore(1000);//<-- we can change
				textField.setText("Arena upgraded");
			}else if (money.getMoney() < arena.getUpgradeCost()){
			
				textField.setText("you don't have enough money to upgrade the arena");
			}
			else{
				System.out.println("Money: " + money.getMoney() + " >= " + arena.getUpgradeCost() + "arena.canUpgrade: " + arena.canUpgrade());
				textField.setText("you can't upgrade the arena at this time");
			}
		}else if(e.getX() > 10 && e.getX() < 120 && e.getY() > 410 && e.getY() < 440){
			//Antidote
			System.out.println("You clicked the Buy antidote button");
			if(money.getMoney() > hospital.getAntidoteCost()){
				money.decreaseMoney(hospital.getAntidoteCost());
				hospital.buyAntidote();
				score.incrementScore(4000);
				textField.setText("You bought the Antidote");
			}else{
				textField.setText("you don't have enough money to buy the antidote");
			}
		}else if(e.getX() > 10 && e.getX() < 120 && e.getY() > 450 && e.getY() < 480){
			//recruit army
			//System.out.println("You clicked the Recruit Army button");
			if(money.getMoney() > police.getArmyCost()){
				if(police.requestAssistance()){
					money.decreaseMoney(police.getArmyCost());
					score.incrementScore(2000);
					textField.setText("Army assistance upgraded");
				}else{
					textField.setText("your army is at max size");
				}
				
			}else{
				textField.setText("you don't have enough money to recruit the army");
			}
		}else if(e.getX() > 10 && e.getX() < 120 && e.getY() > 490 && e.getY() < 520){
			//increase security
			//System.out.println("You clicked the Increase Security button");
			if(money.getMoney() > police.getIncreaseSecurityCost()){
				if(police.increaseSecurity()){
					money.decreaseMoney(police.getIncreaseSecurityCost());
					score.incrementScore(15);
					textField.setText("Inceased Security");
				}else{
					textField.setText("Police force is as big as possible");
				}
			}else{
				textField.setText("you don't have enough money to increase security");
			}
		}else if(e.getX() > 10 && e.getX() < 120 && e.getY() > 560 && e.getY() < 590){
			//on off button for airport
			if(airport.isBuildingOpenOrClosed()){
				airport.closeBuilding();
				textField.setText("Airport is closed");
			}else{
				airport.openBuilding();
				textField.setText("Airport is open");
			}
		}else if(e.getX() > 10 && e.getX() < 120 && e.getY() > 600 && e.getY() < 630){
			//on off button for subway
			if(subway.isBuildingOpenOrClosed()){
				subway.closeBuilding();
				textField.setText("Subway is closed");
			}else{
				subway.openBuilding();
				textField.setText("Subway is open");
			}
		}else if(e.getX() > 10 && e.getX() < 120 && e.getY() > 640 && e.getY() < 670){
			//on off button for arena
			if(arena.isBuildingOpenOrClosed()){
				arena.closeBuilding();
				textField.setText("Arena is closed");
			}else{
				arena.openBuilding();
				textField.setText("Arena is open");
			}
		}else if(e.getX() > 50 && e.getX() < 60 && e.getY() > 770 && e.getY() < 790){
			//fast forward button
			speedUp = true;
			slowDown = false;
			normalSpeed = false;
			delay = 0;
			textField.setText("Speed Up");
		}else if(e.getX() > 30 && e.getX() < 40 && e.getY() > 770 && e.getY() < 790){
			//normal speed button
			speedUp = false;
			slowDown = false;
			normalSpeed = true;
			delay = 1;
			textField.setText("Normal Speed");
		}else if(e.getX() > 10 && e.getX() < 20 && e.getY() > 770 && e.getY() < 790){
			//slow down button
			speedUp = false;
			slowDown = true;
			normalSpeed = false;
			delay = 2;
			textField.setText("Slow Down");
		}else{
			int row_x = e.getX() - 130;// <-- the 100 is the same number as x_offset from the paint function
			int row_y = e.getY();
			row_x = row_x*2/size;
			row_y = row_y*2/size;
			if(row_x >= 0 && row_y >= 0){				
				if(map[row_x][row_y].inQueue() && map[row_x][row_y].getHumanPopulation() != 0 && money.getMoney() > 50){
					//decreases money and increments score when quarentining
					map[row_x][row_y].quarentineBlock();
					score.incrementScore(50);
					money.decreaseMoney(50);
				}
			}
		}
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
}
